package com.rcloud.server.sealtalk.controller.base;


import com.ijpay.wxpay.WxPayApiConfig;
import com.ijpay.wxpay.WxPayApiConfigKit;
import com.rcloud.server.sealtalk.configuration.bean.WxPayBean;
import com.rcloud.server.sealtalk.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author Javen
 */
public class WxPayBaseController extends BaseController {
    @Autowired
    WxPayBean wxPayBean;
    /**
     * 获取微信支付配置
     *
     * @return {@link WxPayApiConfig} 微信支付配置
     */
    public WxPayApiConfig getApiConfig() {
        WxPayApiConfig apiConfig;
        try {
            apiConfig = WxPayApiConfigKit.getApiConfig(wxPayBean.getAppId());
        } catch (Exception e) {
            apiConfig = WxPayApiConfig.builder()
                    .appId(wxPayBean.getAppId())
                    .mchId(wxPayBean.getMchId())
                    .partnerKey(wxPayBean.getPartnerKey())
                    .certPath(wxPayBean.getCertPath())
                    .domain(wxPayBean.getDomain())
                    .build();
        }
        return apiConfig;
    }
}
